#Include <GuiButton.au3>
#Include <GuiComboBox.au3>
#Include <GuiListBox.au3>
#Include <..\include\Common_For_PageManager.au3>
#Include <Excel.au3>
#include <WinAPI.au3>

Global $sFunctionNameOCR = 'Performance'
Global $sFunctionNamePerformance = 'Performance'
Global $sFolderName_Performane = "Performane"
Global $sPMProcessName = "prestopm.exe"
Global $sPerfomresultPDFWriter = "C:\AutomationTest\Performane\Perform Result\PDF Writer\"
Global $sPerfomresultSaveAsRTF = "C:\AutomationTest\Performane\Perform Result\Save As RTF\"
Global $sPerfomresultSaveAsPDF = "C:\AutomationTest\Performane\Perform Result\Save as PDF\"
Global $sPerfomresultMergerPDF = "C:\AutomationTest\Performane\Perform Result\Merger PDF\"
Global $sPerfomresultSplitPDF = "C:\AutomationTest\Performane\Perform Result\Split PDF\"
Global $sPerfomresultScan = "C:\AutomationTest\Performane\Perform Result\Scan\"

Global Const $iOCRTime_MarginOfError                            = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'OCRTime_MarginOfError'))
Global Const $iOCRMemory_MarginOfError                          = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'OCRMemory_MarginOfError'))
Global Const $iOCRHandles_MarginOfError                         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'OCRHandles_MarginOfError'))
Global Const $iOCRGDIObjects_MarginOfError                      = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'OCRGDIObjects_MarginOfError'))
Global Const $iOCRCPUUsage_MarginOfError                        = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'OCRCPUUsage_MarginOfError'))

Global Const $iPrintFileNmaeCtrl                                = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'PrintFileNmaeCtrl'))
Global Const $sPrintSaveBtn                                     = ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'PrintSaveBtn')
Global Const $iPDFWriterTime_MarginOfError                      = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'PDFWriterTime_MarginOfError'))
Global Const $iPDFWriterMemory_MarginOfError                    = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'PDFWriterMemory_MarginOfError'))
Global Const $iPDFWriterHandles_MarginOfError                   = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'PDFWriterHandles_MarginOfError'))
Global Const $iPDFWriterGDIObjects_MarginOfError                = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'PDFWriterGDIObjects_MarginOfError'))
Global Const $iPDFWriterCPUUsage_MarginOfError                  = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'PDFWriterCPUUsage_MarginOfError'))

Global Const $iSaveAsDialogNameEditBox                          = Number(ReadIniKeyValue($sPCodeIniPath, 'Save As', 'SaveAsDialogNameEditBox'))
Dim Const $sSaveAsTypeCtrlInfo 		                        	= Number(ReadIniKeyValue($sPCodeIniPath, 'Save As', 'SaveAsDialogTypeComboBox' ))

Global Const $iSaveAsRTFTime_MarginOfError                      = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsRTFTime_MarginOfError'))
Global Const $iSaveAsRTFMemory_MarginOfError                    = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsRTFMemory_MarginOfError'))
Global Const $iSaveAsRTFHandles_MarginOfError                   = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsRTFHandles_MarginOfError'))
Global Const $iSaveAsRTFGDIObjects_MarginOfError                = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsRTFGDIObjects_MarginOfError'))
Global Const $iSaveAsRTFCPUUsage_MarginOfError                  = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsRTFCPUUsage_MarginOfError'))


Global Const $iSaveAsPDFTime_MarginOfError                      = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsPDFTime_MarginOfError'))
Global Const $iSaveAsPDFMemory_MarginOfError                    = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsPDFMemory_MarginOfError'))
Global Const $iSaveAsPDFHandles_MarginOfError                   = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsPDFHandles_MarginOfError'))
Global Const $iSaveAsPDFGDIObjects_MarginOfError                = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsPDFGDIObjects_MarginOfError'))
Global Const $iSaveAsPDFCPUUsage_MarginOfError                  = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SaveAsPDFCPUUsage_MarginOfError'))

Global Const $iMergePDFTime_MarginOfError                       = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'MergePDFTime_MarginOfError'))
Global Const $iMergePDFMemory_MarginOfError                     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'MergePDFMemory_MarginOfError'))
Global Const $iMergePDFHandles_MarginOfError                    = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'MergePDFHandles_MarginOfError'))
Global Const $iMergePDFGDIObjects_MarginOfError                 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'MergePDFGDIObjects_MarginOfError'))
Global Const $iMergePDFCPUUsage_MarginOfError                   = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'MergePDFCPUUsage_MarginOfError'))

Global Const $iSplitPDFTime_MarginOfError                       = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SplitPDFTime_MarginOfError'))
Global Const $iSplitPDFMemory_MarginOfError                     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SplitPDFMemory_MarginOfError'))
Global Const $iSplitPDFHandles_MarginOfError                    = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SplitPDFHandles_MarginOfError'))
Global Const $iSplitPDFGDIObjects_MarginOfError                 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SplitPDFGDIObjects_MarginOfError'))
Global Const $iSplitPDFCPUUsage_MarginOfError                   = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SplitPDFCPUUsage_MarginOfError'))

Global Const $iScanTime_MarginOfError                           = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanTime_MarginOfError'))
Global Const $iScanMemory_MarginOfError                         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanMemory_MarginOfError'))
Global Const $iScanHandles_MarginOfError                        = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanHandles_MarginOfError'))
Global Const $iScanGDIObjects_MarginOfError                     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanGDIObjects_MarginOfError'))
Global Const $iScanCPUUsage_MarginOfError                       = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanCPUUsage_MarginOfError'))

Global Const $iScanButtonTime_MarginOfError                     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanButtonTime_MarginOfError'))
Global Const $iScanButtonMemory_MarginOfError                   = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanButtonMemory_MarginOfError'))
Global Const $iScanButtonHandles_MarginOfError                  = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanButtonHandles_MarginOfError'))
Global Const $iScanButtonGDIObjects_MarginOfError               = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanButtonGDIObjects_MarginOfError'))
Global Const $iScanButtonCPUUsage_MarginOfError                 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'ScanButtonCPUUsage_MarginOfError'))


Global Const $sSplitPDFPerformResultFolderTitleInPM             = ReadIniKeyValue($sPCodeIniPath, $sSectionNameProformance, 'SplitPDFPerformResultFolderTitleInPM')

Func InitializeStatusForPerformance_OCR()
EndFunc

Func InitializeStatusForPerformance_SaveAsRTF()
	FileDelete($sPerfomresultSaveAsRTF & "*.*")
	$sTitle = 'Save As'
	$sText = 'FolderView'
	While WinExists($sTitle, $sText)
		WinActivate($sTitle, $sText)
		Send('{ESC}')
		Sleep(3000)
	WEnd
EndFunc

Func InitializeStatusForPerformance_SaveAsPDF()
	FileDelete($sPerfomresultSaveAsPDF & "*.*")
	$sTitle = "[CLASS:#32770]"
	$sText = 'FolderView'
	While WinExists($sTitle, $sText)
		WinActivate($sTitle, $sText)
		Send('{ESC}')
		Sleep(3000)
	WEnd
	
	While ProcessExists('WINWORD.EXE')
		ProcessClose('WINWORD.EXE')
		Sleep(500)
	WEnd
	While ProcessExists('POWERPNT.EXE')
		ProcessClose('POWERPNT.EXE')
		Sleep(500)
	WEnd
	
EndFunc

Func InitializeStatusForPerformance_ScanButton()
	If WinExists('ScanGear') Then
		ControlClick('ScanGear','', 'Button1')
		Sleep(1000)
	EndIf
EndFunc

Func ClickButtonInPMSB($sBtn, $TestCaseID, $sFunctionName)
	Local $Scancentraltitile = 'Scan Central'
	$h = ControlGetHandle($sPMSBBWndTitle, '', $sPMSBToolBar)
	If $h <> '' Then
		If Not @error Then
			Switch $sBtn
			Case 'Scan to PM'
				_GUICtrlToolbar_ClickIndex($h, 0)
				Sleep(1000)
			EndSwitch
			Return True
		EndIf	
	EndIf	
	ControlClick($Scancentraltitile, '', 32794)   ;scan to pm button in scan central
	Sleep(1000)
	Return True
	#cs
	If WinWaitActive($sPMSBBWndTitle, '', 15) Then
		Sleep(500)
		WinActivate('Presto! Scan Buttons')
		$h = ControlGetHandle($sPMSBBWndTitle, '', $sPMSBToolBar)
		If Not @error Then
			Switch $sBtn
			Case 'Scan to PM'
				_GUICtrlToolbar_ClickIndex($h, 0)
				Sleep(1000)
			EndSwitch
			Return True
		EndIf
	ElseIf WinWaitActive($Scancentraltitile, '', 15) Then
		Sleep(500)
		WinActivate($Scancentraltitile)
		ControlClick($Scancentraltitile, '', 32794)   ;scan to pm button in scan central
		Sleep(1000)
		Return True
	EndIf
	#ce
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'ClickButtonInPMSB($sBtn, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False
EndFunc

Func ClickPMSBButtonInToolBar($hPMHandle,$TestCaseID, $sFunctionName)
	ControlClick($hPMHandle, '', $iPMSBButtonInToolbar)
	If Not @error Then
		Sleep(1000)
		If ProcessExists('Pmsb.exe') Then
			Return True
		EndIf
	EndIf
	If Not @error Then
		Sleep(1000)
		If ProcessExists('Scan Central.exe') Then
			Return True
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'ClickPMSBButtonInToolBar($hPMHandle,$TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False
EndFunc


Func InitializeStatusForPerformance_Scan()
	If WinExists('ScanGear') Then
		ControlClick('ScanGear','', 'Button1')
		Sleep(1000)
	EndIf
	FileDelete($sPerfomresultScan & "*.*")
	$sTitle = 'Save As'
	$sText = 'FolderView'
	While WinExists($sTitle, $sText)
		WinActivate($sTitle, $sText)
		Send('{ESC}')
		Sleep(3000)
	WEnd
EndFunc

Func InitializeStatusForPerformance_PDFWriter()
	FileDelete($sPerfomresultPDFWriter & "*.*")
	$sTitle = 'Save As'
	$sText = 'FolderView'
	While WinExists($sTitle, $sText)
		WinActivate($sTitle, $sText)
		Send('{ESC}')
		Sleep(3000)
	WEnd
EndFunc

Func InitializeStatusForPerformance_MergerPDF()
	FileDelete($sPerfomresultMergerPDF & "*.*")
	$sTitle = 'Save As'
	$sText = 'FolderView'
	While WinExists($sTitle, $sText)
		WinActivate($sTitle, $sText)
		Send('{ESC}')
		Sleep(3000)
	WEnd
EndFunc

Func InitializeStatusForPerformance_SplitPDF()
	FileDelete($sPerfomresultSplitPDF & "*.*")
	$sTitle = 'Save As'
	$sText = 'FolderView'
	While WinExists($sTitle, $sText)
		WinActivate($sTitle, $sText)
		Send('{ESC}')
		Sleep(3000)
	WEnd
EndFunc

Func OpenSaveAsDialog()
	Send('!f')
	Sleep(500)
	Send('s')
	Sleep(1000)
EndFunc

Func OpenSaveAsPDFDialog()
	Send('!f')
	Sleep(500)
	Send('d')
	Sleep(1000)
EndFunc

Func SaveAsToRTF($File, $TestCaseID, $sFunctionName)
	If WinWaitActive("[CLASS:#32770]", "FolderView", 20) Then
		Sleep(500)
		If ControlSetText("[CLASS:#32770]", "FolderView", $iSaveAsDialogNameEditBox, $File) Then
			Sleep(300)
			If ControlClick("[CLASS:#32770]", "FolderView", $sSaveAsTypeCtrlInfo) Then
				Sleep(500)
				Send("r")
				Sleep(200)
				Send("{ENTER}")
				Sleep(500)
				If ControlClick("[CLASS:#32770]", "FolderView", 'Button2') Then Return True
			EndIf
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'SaveAsToRTF($File, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False
EndFunc

Func SaveAsPDF($File, $TestCaseID, $sFunctionName)
	If WinWaitActive("[CLASS:#32770]", "FolderView", 20) Then
		Sleep(500)
		If ControlSetText("[CLASS:#32770]", "FolderView", 1152, $File) Then
			Sleep(300)
			If ControlClick("[CLASS:#32770]", "FolderView", 'Button2') Then Return True
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & ' SaveAsPDF($File, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False
EndFunc

Func WaitSplitPDFFinished($sTime, $hPMHandle, $sTtile, $TestCaseID, $sFunctionName)
	MsgBox('','',$sTtile)
	If WinWait($sTtile, '', 300)  Then 
		Return True
	EndIf
	#cs
	For $i = 1 to $sTime
		Sleep(1000)
		If WinGetTitle($hPMHandle) == $sTtile  Then 
		If WinWait($sTtile, '', )  Then 
			Return True
		EndIf
	Next	
	#ce
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'WaitSplitPDFFinished($sTime, $hPMHandle, $sTtile, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False
EndFunc


Func WaitUntilPrintFinished($File, $sTime, $TestCaseID, $sFunctionName)
	For $i = 1 to $sTime
		Sleep(1000)
		If FileExists($File) Then Return True
	Next
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'WaitUntilPrintFinished($File, $sTime)', $TestCaseID, $sFunctionName, ' ')
	Return False
EndFunc

Func SelectAllItems($hThumbnailView)
	;Select All items.
	_GUICtrlListView_ClickItem($hThumbnailView, 0, "left", True) 
	Sleep(400)
	Send('!e')
	Sleep(500)
	Send('s')
	Sleep(500)
	Send('s')
	Sleep(500)
	Send('{ENTER}')
	Sleep(800)
EndFunc

Func _SelectAllItems($hThumbnailView)
	;Select All items.
	_GUICtrlListView_ClickItem($hThumbnailView, 0, "left", True) 
	Sleep(400)
	Send('^a')
	Sleep(800)
EndFunc

Func PerformOCR()
	Send('!t')
	Sleep(500)	
	Send('o')
	Common_SleepTime(10)
EndFunc

Func WaitOCRFinished($iTime,$TestCaseID, $sFunctionName)
	If WinWaitClose('OCR','Cancel',$iTime) Then Return True
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'WaitOCRFinished($iTime,$TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False
EndFunc

Func SelectPMPDFWriter()
	Send('!f')
	Sleep(500)	
	Send('p')
	Sleep(500)
	Send('p')
	Sleep(500)
	Send('{RIGHT}')
	Sleep(500)
	Send('{ENTER}')
EndFunc

Func OpenMergePDFDlg()
	Send('!t')
	Sleep(500)	
	Send('m')
	Sleep(500)
	Send('{ENTER}')
	Sleep(500)
EndFunc

Func OpenSplitPDFDlg()
	Send('!t')
	Sleep(500)	
	Send('s')
	Sleep(500)
	Send('s')
	Sleep(500)
	Send('s')
	Sleep(500)
	Send('{ENTER}')
	Sleep(500)
EndFunc

Func GetThumbinalHdanle($hPMHandle, $TestCaseID, $sFunctionName)
	$h = ControlGetHandle($hPMHandle, "", $sThumbnailViewCtrInfo)
	If $h = '' Then
		Common_ClosePMWhenException()
		Common_WriteLog($sFaile & 'GetThumbinalHdanle($hPMHandle, $TestCaseID, $sFunctionName))', $TestCaseID, $sFunctionName, ' ')
		Return False
	Else
		Return $h
	EndIf
EndFunc


Func PrintFiles($sFileName, $TestCaseID, $sFunctionName)
	$sTitle = 'Save As'
	;$sText = 'FolderView'
	$sText = ''
	If WinWait($sTitle, $sText , 60) Then
		Sleep(10000)
		WinActivate($sTitle, $sText)
		If ControlGetHandle($sTitle, $sText, $iPrintFileNmaeCtrl) Then
			ControlSetText($sTitle, $sText, $iPrintFileNmaeCtrl, $sFileName)
			Sleep(300)
			WinActivate($sTitle, $sText)
			ControlClick($sTitle, $sText, $sPrintSaveBtn)
			If Not @error Then Return True
		Else
			ControlSetText($sTitle, $sText, 1001, $sFileName)		
			If Not @error Then
				Sleep(300)
				WinActivate($sTitle, $sText)
				ControlClick($sTitle, $sText, 'Button1')
				If Not @error Then Return True
			EndIf
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'PrintFiles($sFileName, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
EndFunc

Func MergePDF($sFileName, $TestCaseID, $sFunctionName)
	$sTitle =  "[CLASS:#32770]"
	$sText = 'FolderView'
	If WinWait($sTitle, $sText , 60) Then
		Sleep(10000)
		WinActivate($sTitle, $sText)
		ControlSetText($sTitle, $sText, 1152, $sFileName)
		If Not @error Then
			Sleep(300)
			WinActivate($sTitle, $sText)
			ControlClick($sTitle, $sText, 'Button2')
			If Not @error Then Return True
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'MergePDF($sFileName, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
EndFunc

Func SplitPDF($TestCaseID, $sFunctionName)
	$sTitle =  "[CLASS:#32770]"
	$sText = 'File Name'
	$stitle1 = "Browse For Folder"
	If WinWait($sTitle, $sText , 60) Then
		Sleep(7000)
		WinActivate($sTitle, $sText)
		ControlClick($sTitle, $sText, 1103)    ;Brose button.
		If WinWait($stitle1,'OK', 10) Then
			WinActivate($stitle1, 'OK')
			Local $hTree = ControlGetHandle($stitle1, "OK", 'SysTreeView321')
			Local $hItemFound1 = _GUICtrlTreeView_FindItem($hTree, @UserName)
			_GUICtrlTreeView_Expand($hTree,$hItemFound1,False)
			Sleep(300)
			Local $hItemFound2 = _GUICtrlTreeView_FindItem($hTree, 'Computer')
			_GUICtrlTreeView_Expand($hTree,$hItemFound2)	
			Sleep(300)
			Local $hItemFound3 = _GUICtrlTreeView_FindItem($hTree, $sDiskC_DiskVolumeName)
			_GUICtrlTreeView_Expand($hTree,$hItemFound3)	
			Sleep(300)
			Local $hItemFound4 = _GUICtrlTreeView_FindItem($hTree, 'AutomationTest')
			_GUICtrlTreeView_Expand($hTree, $hItemFound4)	
			Sleep(300)
			Local $hItemFound5 = _GUICtrlTreeView_FindItem($hTree, 'Performane')
			_GUICtrlTreeView_Expand($hTree, $hItemFound5)	
			Sleep(300)
			Local $hItemFound6 = _GUICtrlTreeView_FindItem($hTree, 'Perform Result')	
			_GUICtrlTreeView_Expand($hTree, $hItemFound6)
			Sleep(300)
			Local $hItemFound7 = _GUICtrlTreeView_FindItem($hTree, 'Split PDF')	
			_GUICtrlTreeView_Expand($hTree, $hItemFound7)
			Sleep(300)			
			_GUICtrlTreeView_SelectItem($hTree, $hItemFound7)	
			Sleep(300)
			ControlClick('Browse For Folder','OK',1)
			Common_SleepTime(2)		
			ControlClick($sTitle, $sText, 'Button1')
			If Not @error Then Return True
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'SplitPDF($TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
EndFunc

Func SwitchToSampleFodler($sFolderName_, $hPMHandle, $sFolderName, $TestCaseID, $sFunctionName)
	If Common_SwitchToFunctionFolder($hPMHandle, $sFolderName, $TestCaseID, $sFunctionName) Then
		Local $hTree = ControlGetHandle($hPMHandle, "", $sTreeViewCtrInfo)
		Local $hItemFound = _GUICtrlTreeView_FindItem($hTree, 'Sample')
		If Not @error Then
			_GUICtrlTreeView_Expand($hTree,$hItemFound, True)
			Sleep(500)
			Local $hItemFound2 = _GUICtrlTreeView_FindItem($hTree, $sFolderName_)
			If Not @error Then	
				_GUICtrlTreeView_ClickItem($hTree, $hItemFound2)
				If Not @error Then 
					Common_SleepTime(20)	
					Return True
				EndIf	
			EndIf	
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'SwitchToOCRSampleFodler($sFolderName_, $hPMHandle, $sFolderName, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False			
EndFunc

Func SwitchToPerformResultFodler($sFolderName_, $hPMHandle, $sFolderName, $TestCaseID, $sFunctionName)
	If Common_SwitchToFunctionFolder($hPMHandle, $sFolderName, $TestCaseID, $sFunctionName) Then
		Local $hTree = ControlGetHandle($hPMHandle, "", $sTreeViewCtrInfo)
		Local $hItemFound = _GUICtrlTreeView_FindItem($hTree, 'Perform Result')
		If Not @error Then
			_GUICtrlTreeView_Expand($hTree,$hItemFound, True)
			Sleep(500)
			Local $hItemFound2 = _GUICtrlTreeView_FindItem($hTree, $sFolderName_)
			If Not @error Then	
				_GUICtrlTreeView_ClickItem($hTree, $hItemFound2)
				If Not @error Then 
					Common_SleepTime(20)	
					Return True
				EndIf	
			EndIf	
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'SwitchToPerformResultFodler($sFolderName_, $hPMHandle, $sFolderName, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False			
EndFunc

Func GetProcessCPUUseage($ioProcName)
    Dim $output, $arr
	If ProcessExists($sprocessName) == 0 Then Return 'PM crashed!'
	Dim $list = ProcessList($ioProcName)
	If Not @error Then
		$output = StringStripWS(_get_cmd_output('C:\AutomationTest\All_Script(EXE files)\Tools\' & "\pslist.exe -s 2 -r 1 " & $list[1][1]), 7)
		$arr = StringSplit(StringTrimLeft($output, StringInStr($output, $list[1][1], -1, 2) + StringLen($list[1][1])), " ")
		Return $arr[1]
	EndIf
EndFunc

Func _get_cmd_output($cmd)

    Dim $cmd_timeout = 3000, $pid, $timer, $output

    $pid = Run($cmd,@WorkingDir,@SW_HIDE,2)
    $timer = TimerInit()
    while ProcessExists($pid)
        sleep(50)
        If TimerDiff($timer) > $cmd_timeout Then ProcessClose($pid)
    WEnd
    $output = StdoutRead($pid)

    Return StringStripCR($output)
EndFunc

Func GetProcessHandles ($ioProcName)
	If ProcessExists($sprocessName) == 0 Then Return 'PM crashed!'
    Local $sStatus = Run(@ComSpec & " /c WMIC PROCESS WHERE Name='" & $ioProcName & "' GET handlecount", @SystemDir, @SW_HIDE, 8)
    Local $sBuf
    While 1
        $sBuf &= StdoutRead($sStatus)
        If @Error then ExitLoop ; We have lift off, let's go!
    WEnd
    $sBuf = StringStripCR($sBuf)
    $sBuf = StringRegExpReplace($sBuf, "HandleCount", "")
    $sBuf = StringStripWS($sBuf, 3)
    Return $sBuf
EndFunc

Func GetProcessGDIObjects ($ioProcName)
	Local Const $GR_GDIOBJECTS = 0
	Local Const $iAccess = 2035711
	Local Const $fInherit = 0
	Local $PID = ProcessExists($ioProcName)
	If $PID == 0 Then Return 'PM crashed!'
	Local $hProc = _WinAPI_OpenProcess($iAccess, $fInherit, $PID)
	Return _WinAPI_GetGuiResources($GR_GDIOBJECTS, $hProc)
EndFunc

Func GetProcessPrivateMemory($sprocessName)
	$pid = ProcessExists($sprocessName)
	If $pid == 0 Then Return 'PM crashed!'
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"

    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
       For $objItem In $colItems
          If $pid = $objItem.IDProcess Then Return ($objItem.WorkingSetPrivate / 1024)
       Next
    Endif
    Return 0
EndFunc

Func WriteTextCaseInfo ($sLogMsg,$sFunctionName,$iFlag = -1)
	Dim $Log_Path = @DesktopDir & "\"
	Local $sFileName = $sFunctionName&".Log"
	Local $sMsg, $iWriteFile, $hOpenFile, $iOpenMode = 1 
    $sMsg = @CRLF & $sLogMsg 
	If $iFlag <> -1 Then
		$sMsg &= @CRLF & FileRead ($Log_Path&$sFileName)
		$iOpenMode = 2
	EndIf
	$hOpenFile = FileOpen ($Log_Path & $sFileName, 129)
	If $hOpenFile = -1 Then Return SetError(1, 0, 0)
	$iWriteFile = FileWriteLine ($hOpenFile, $sMsg)
	If $iWriteFile = -1 Then Return SetError (2, 0, 0)
	
	Return FileClose ($hOpenFile)
EndFunc 




